package cn.gok.controller;

import cn.gok.UserService;
import cn.gok.entity.User;
import cn.hutool.json.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @Description:
 * @Author: chen fan
 * @Date: 2022年10月31日 17:52:07
 */
@WebServlet("/login")
public class UserController extends HttpServlet {

    private  UserService userService = new UserService();

    @Override
    protected void service(HttpServletRequest req,
                           HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("userName");
        String password = req.getParameter("password");

        User user = new User(userName,password);
        Map<String, String> result = userService.login(user);
        resp.setContentType("json/application;charset=utf8");
        resp.getWriter().println(JSONUtil.toJsonStr( result ));
    }
}
